home *** CD-ROM | disk | FTP | other *** search
/ Executor 2.0 / executorv2.0.iso / mac / demoware / Asymptote 1.1 Demo / Scripts / Demos / 14) Gaussian Fit / demo14 next >
Encoding:
Text File  |  1994-11-01  |  1.3 KB  |  48 lines  |  [TEXT/DWat]

  1. % A demonstration of non-linear curve
  2. % fitting in Asymptote.
  3.  
  4. % Fit a double Gaussian to a spectrum.
  5. % Ask the user if they would like to use
  6. % preset initial guesses for the parameters
  7. % of the Gaussians or if they would like
  8. % to enter the parameters using the graph
  9. % cursor.
  10.  
  11. % Set up and read the data file
  12. fullscreen yes
  13. datafile Gaussian Data
  14. datalines 2
  15. readcol x 1
  16. readcol y 2
  17. close \f
  18. rpn 4 >e    % Put a constant error of 4 in the e vector
  19. graphlimits
  20. pointsymbol 4 cross
  21. plotpoints
  22. drawframe
  23. drawxlabel Frequency
  24. drawylabel Intensity
  25.  
  26. % Ask whether they want to use the mouse
  27. % to enter guesses for the Gaussian parameters
  28. set GetParameters no
  29. ask GetParameters Yes No I need guesses for the fit parameters.                       $
  30. Would you like to enter them with the graph cursor?
  31.  
  32. % Run the appropriate script
  33. if GetParameters then GetParameters else SetParameters
  34.  
  35. % Now do the fit
  36. set plot_each_fit yes
  37. fitxy 6 x a0 - a1 / 2 y^x -1 * e^x a2 * x a3 - a4 / 2 y^x -1 * e^x a5 * + 
  38.  
  39. % To plot the fit, use four times as many points:
  40. npts npts 4 *
  41. % Which fill the entire graph range:
  42. xrange xleft xright
  43. close xrange    % Close the xrange script
  44.  
  45. % Calculate the fit at each x
  46. rpn <x a0 - a1 / 2 y^x -1 * e^x a2 * <x a3 - a4 / 2 y^x -1 * e^x a5 * +  >y
  47. % Plot the fit on the graph
  48. plotline